#include "SinhVien.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

char * DocFile(char * cTenFile)
{
	char *kq = new char;
	ifstream myfile;
	myfile.open(cTenFile);
	while (!myfile.eof())
	{
		myfile>>kq;
	}
	//printf("%s\n", kq);
	
	myfile.close();
	//printf("%s\n", kq);
	return kq;
}

//int TimKiTu(string strTest, string strTim)
//{
//	int viTriTimThay = -1;
//	for (int i = 0; i < strTest.length(); i++)
//	{
//		//for (int j = 0; j < strTim.length(); j++)
//		//{
//			if (strTest[i] == "\t")
//			//{
//				viTriTimThay = i;
//			//}
//		//}
//	}
//	return viTriTimThay;
//}

std::string DocFileGetLine(char * cTenFile)
{
	int count = 0;
	char* ten;
	int gioiTinh, diem;
	char* ngaySinh;
	SinhVien sv;
//	Date ngaySinh;
	std::string test("");
	ifstream myfile;
	myfile.open(cTenFile);
	while (getline(myfile,test)) 
	{
		// xu ly tung dong
		char* ptrSplit;
		ptrSplit = strtok ((char*)test.c_str(),"\t");
		while (ptrSplit != NULL)
		{
			count++;
			if(count == 1)
			{
				ten = ptrSplit;
			}
			if(count == 2)
			{
				ngaySinh = ptrSplit;
			}
			if(count == 3)
			{
				gioiTinh = (int)ptrSplit;
			}
			if(count == 4)
			{
				diem = (int)ptrSplit;
			}
			ptrSplit = strtok (NULL, "\t");
		}

		//cout<<ngaySinh<<" ten = "<<ten<<endl;

		char* ptrNgaySinh;
		ptrNgaySinh = strtok (ngaySinh,"/");
		while (ptrNgaySinh != NULL)
		{
			printf ("%s\n",ptrNgaySinh);
			ptrNgaySinh = strtok (NULL, "/");
		}
	}
	myfile.close();
	return test;
}



int main()
{
	/*Date ngay(2,4,1989);
	ngay.InDate();
	
	SinhVien svA("Tran Duc Thang", ngay, 0, 5.8);
	svA.InSinhVien();
	SinhVien svB;
	svB.setName(svA.getName());
	svB.InSinhVien();
	svA.setName("Tran Duc Toan");
	svA.InSinhVien();*/


	/*SinhVien sv;

	string line;
	ifstream myfile ("DuLieu.txt");


	myfile.close();*/

	DocFileGetLine("DuLieu.txt");
	

	
	
	system("pause");
}